from ninja import NinjaAPI

from apps.agent_applets.apis import agent_router
from apps.manager.apis import manager_router
from apps.user_applets.apis import applets_router
from utils.auth import InvalidToken, InvalidPermission

api = NinjaAPI(title="NinjaAPI-潜脉")
api.add_router("/manager", manager_router)
api.add_router("/applets", applets_router)
api.add_router("/agent", agent_router)


@api.exception_handler(InvalidToken)
def on_invalid_token(request, exc):
    return api.create_response(request, {"error": "Invalid token", "code": 401}, status=200)


@api.exception_handler(InvalidPermission)
def on_invalid_permission(request, exc):
    return api.create_response(request, {"error": "Invalid permission", "code": 403}, status=200)